using System;

namespace XospitalParser.stats
{
    public class UserInfo : IComparable<UserInfo>
    {
        public UserInfo(string name, string ip)
        {
            Name = name;
            Ip = ip;
        }

        public string Name { get; set; }
        public string Ip { get; set; }

        public int CompareTo(UserInfo other)
        {
            if (other == null) return -1;
            return (Name + Ip).CompareTo(other.Name + other.Ip);
        }

        public override string ToString()
        {
            return string.Format("{0} ({1})", Name, Ip);
        }

        public bool Equals(UserInfo other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;
            return Equals(other.Name, Name) && Equals(other.Ip, Ip);
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != typeof (UserInfo)) return false;
            return Equals((UserInfo) obj);
        }

        public override int GetHashCode()
        {
            unchecked
            {
                return ((Name != null ? Name.GetHashCode() : 0)*397) ^ (Ip != null ? Ip.GetHashCode() : 0);
            }
        }
    }
}